script: footprint: Improve C++ static variable reporting #96573
+27
−11
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
script: footprint: Improve C++ static variable reporting
This commit enhances the
size_report
script to correctly categorize static C++ variables in the memory report tree. Previously, these variables were incorrectly grouped under the "No paths" category.Problem Description
The
size_report.py
script uses DWARF debug information and ELF symbol tables to map memory usage to source file paths. While this system works well for C and most C++ functions, a specific limitation exists for C++ static variables.DW_TAG_subprogram
) are typically defined by an address range (DW_AT_low_pc
toDW_AT_high_pc
). In contrast, variables (DW_TAG_variable
) are represented by a single, specific address (DW_AT_location
).This behaviour gives a misleading view of memory usage for C++ applications with static members, as a significant portion of the memory footprint could be incorrectly attributed to the "No paths" section.
Solution
This change introduces a more robust address-based mapping system within the
do_address_range_matching
function.DW_TAG_subprogram
) and variables (DW_TAG_variable
) from the DWARF information.DW_AT_location
address.This solution ensures that static C++ variables are correctly mapped to their source files by using the most reliable piece of information available: the memory address. This approach is more robust than name-based matching, as it bypasses C++'s name mangling complexities and handles all symbols based on their location in memory.
Impact
This enhancement provides a more accurate and detailed memory footprint report for C++ applications, allowing developers to better understand and optimize memory usage. Static C++ variables will now be correctly nested under their respective file paths in the report tree, providing a clearer overview of the binary's composition.